//
//  deleteGuest.m
//  QRMaster
//
//  Created by myApple on 15/10/15.
//  Copyright (c) 2015年 myApple. All rights reserved.
//

#import "deleteGuest.h"
#import "StaffModel.h"
#import <UIKit/UIKit.h>

@implementation deleteGuest

+(NSString *)deleteGuest:(NSMutableArray *)array inAllGuestArray:(NSMutableArray *)allArray
{
    NSArray * sortArray = nil;
    if (array.count == 1) {
        sortArray = [array copy];
    }
    //排序
    else
    {
        sortArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath *obj1, NSIndexPath *obj2) {
            if (obj1.row > obj2.row) {
                return NSOrderedAscending;
            }
            else
            {
                return NSOrderedDescending;
            }
            
        }];
    }
    NSMutableString * memberIdString = [[NSMutableString alloc]init];
    //从大到小删除
    for (int i = (int)sortArray.count - 1; i >= 0 ; i --) {
        NSInteger row = [[sortArray objectAtIndex:i]row];
        GuestModel * model = allArray[row];
        [memberIdString appendString:model.guestid];
        [memberIdString appendString:@","];
//        [allArray removeObjectAtIndex:row];//删除数据源
    }
    
    /*
     删除 guesttableview 和 deleteguestcell 的顺序颠倒就会崩掉
     */
    @try {
        NSRange range;
        range.location = memberIdString.length - 1;
        range.length = 1;
        [memberIdString deleteCharactersInRange:range];
    }
    @catch (NSException *exception) {
        return nil;
    }
    
    return memberIdString;

}

+(NSString *)deleteStaff:(NSMutableArray *)array  inAllGuestArray:(NSMutableArray *)allArray
{
    
    NSArray * sortArray = nil;
    if (array.count == 1) {
        sortArray = [array copy];
    }
    //排序
    else
    {
        sortArray = [array sortedArrayUsingComparator:^NSComparisonResult(NSIndexPath *obj1, NSIndexPath *obj2) {
            if (obj1.row > obj2.row) {
                return NSOrderedAscending;
            }
            else
            {
                return NSOrderedDescending;
            }
            
        }];
     
    }
    NSMutableString * memberIdString = [[NSMutableString alloc]init];
    for (NSIndexPath * deleteIndex in sortArray) {
        StaffModel * staffModel = allArray[deleteIndex.row];
        [memberIdString appendString:staffModel.userID];
        [memberIdString appendString:@","];
//        [allArray removeObjectAtIndex:deleteIndex.row];
    }
    @try {
        NSRange range;
        range.location = memberIdString.length - 1;
        range.length = 1;
        [memberIdString deleteCharactersInRange:range];
    }
    @catch (NSException *exception) {
        return nil;
    }
    return memberIdString;
}

@end
